#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <LockInfo/Plugin.h>

#import "FWListViewDelegate.h"
#import "FWToolbarViewCell.h"
#import "FWTransToolbar.h"
#import "FWCommon.h"
#import "FWBadgeView.h"
#import "FWApplication.h"


@implementation FWBarButtonItem

@synthesize tableView;

@end


@implementation FWToolbarViewCell

@synthesize toolbar, toolbarHeight, backgroundImage;

static CGFloat const kMinToolbarHeight = 20;
static CGFloat const kToolbarIconHeight = 16;
static CGFloat const kToolbarSeparatorWidth = 2;


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (id)initWithFrame:(CGRect)frame table:(LITableView *)table toolbarItems:(NSArray*)navItems
{
    if (self = [super initWithFrame:CGRectZero]) {
        toolbarHeight = frame.size.height;

        self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        self.contentMode = UIViewContentModeRedraw;
        self.autoresizesSubviews = YES;
        self.backgroundColor = [UIColor clearColor];
        
        FWTransToolbar* tb = [[FWTransToolbar alloc] initWithFrame:CGRectZero];
        tb.requiredHeight = 16;
        tb.autoresizingMask = UIViewAutoresizingNone;
        tb.barStyle = UIBarStyleBlackTranslucent;
        tb.items = navItems;

        UIImageView* iv = [[UIImageView alloc] init];
        
        self.toolbar = tb;
        self.backgroundImage = iv;

        [self addSubview:iv];
        [self addSubview:tb];
        
        [tb release];
        [iv release];
        
        [self setNeedsLayout];
    }

    return self;
}

- (void)dealloc
{
    [toolbar release];
    [backgroundImage release];
    
    [super dealloc];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Item layout and dimensioning

- (void)layoutSubviews
{
    CGRect rect = self.superview.bounds;

    toolbar.frame = CGRectMake(0, 0, rect.size.width, toolbarHeight);
    self.frame = CGRectMake(0, 0, rect.size.width, toolbarHeight);
    backgroundImage.frame = self.frame;
    
    [self setNeedsDisplay];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Drawing and updating

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Attribute and information access

- (NSArray*)items
{
    return toolbar.items;
}

- (void)setItems:(NSArray*)newItems
{
    [toolbar setItems:newItems animated:YES];
}

- (void)setBackgroundWithImage:(UIImage*)image
{
    backgroundImage.image = image;
}

@end
